package com.cloud.spring;

import org.springframework.beans.factory.FactoryBean;

/**
 * 接口实例工厂，这里主要是用于提供接口的实例对象
 */
public class ServiceFactory<T> implements FactoryBean<T> {

	private Object controller;

	public ServiceFactory(Object controller) {
		this.controller = controller;
	}

	@Override
	public T getObject() throws Exception {
		// 这里主要是创建接口对应的实例，便于注入到spring容器中
		return (T) new CglibProxy(controller).getProxyInstance();
	}

	@Override
	public Class<T> getObjectType() {
		return (Class<T>) controller.getClass();
	}

	@Override
	public boolean isSingleton() {
		return true;
	}
}